from django.db import models
from .subject import Subject
from .base_model import BaseModel

class Chapter(BaseModel):
    subject = models.ForeignKey(Subject, on_delete=models.CASCADE, related_name='chapters', verbose_name='学科')
    name = models.CharField(max_length=100, verbose_name='章节名称')
    description = models.TextField(blank=True, null=True, verbose_name='章节描述')
    order = models.PositiveIntegerField(default=0, verbose_name='排序')

    class Meta:
        verbose_name = '章节'
        verbose_name_plural = '章节'
        ordering = ['order']
        unique_together = ['subject', 'name']

    def __str__(self):
        return f'{self.subject.name} - {self.name}'